package com.chenyongjing.design.pattern.memento.editor;

/**
 * @Author chen
 * @Date 2022/11/23 22:50
 */
public class Test {

    public static void main(String[] args) {
        DraftsBox draftsBox = new DraftsBox();

        Editor editor = new Editor("编辑了第一次","第一次编辑内容","./img/first.png");
        // 添加快照
        ArticleMemento articleMemento =editor.saveToMemento();
        draftsBox.addMemento(articleMemento);

        System.out.println(editor.toString());
        System.out.println("首次修改后的内容======================");
        editor.setTitle("第二次编辑");
        editor.setContent("第二次编辑内容");
        System.out.println(editor.toString());

        articleMemento= editor.saveToMemento();
        draftsBox.addMemento(articleMemento);

        System.out.println("保存到草稿箱==========================");

        System.out.println("第二次修改后的内容======================");
        editor.setTitle("第三次编辑");
        editor.setContent("第三次编辑内容");
        System.out.println(editor.toString());

        System.out.println("撤销第三次编辑");
        articleMemento = draftsBox.getMemento();
        // 撤销到指定的快照
        editor.undoFromMemento(articleMemento);
        System.out.println("撤销第三次编辑后内容=====================");
        System.out.println(editor.toString());

    }
}
